package com.csnf.service.impl;

import com.csnf.feign.OrderFeignClient;
import com.csnf.feign.StorageFeignClient;
import com.csnf.service.BuyService;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BuyServiceImpl implements BuyService {

    @Autowired
    StorageFeignClient  storageFeignClient;
    @Autowired
    OrderFeignClient orderFeignClient;

    @GlobalTransactional
    @Override
    public void buy(String userId, String productCode, int count) {
        //1，远程调用库存服务  扣减库存
        storageFeignClient.updateStorage(productCode,count);

        //2，远程调用订单服务   生成订单
        orderFeignClient.addOrder(userId,productCode,count);

    }
}
